import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_yres/tool/constant.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';
import 'card_add_page.dart';
class CardListPage extends StatefulWidget {
  CardListPage({Key key}) : super(key: key);
  @override
  _CardListPageState createState() => _CardListPageState();
}

class _CardListPageState extends State<CardListPage> {
  EasyRefreshController _controller = new EasyRefreshController();
  double _listHeight = ScreenUtil.getInstance().setHeight(170); //单个列表高度
  double _footerHeight= ScreenUtil.getInstance().setHeight(100);
  List cards = ['', ''];
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('银行卡'),
      ),
      body: Stack(
        children: <Widget>[
          Container(
              height: ScreenUtil.getInstance().setHeight(1334),
              child: EasyRefresh(
                  //刷新  加载组件
                  controller: _controller,
                  child: CustomScrollView(
                    slivers: <Widget>[
                      SliverFixedExtentList(
                          delegate: SliverChildBuilderDelegate(_buildListItem,
                              childCount: cards.length),
                          itemExtent: _listHeight)
                    ],
                  ),
                  onRefresh: () async {},
                  onLoad: () async {}))
        ],
      ),
      bottomNavigationBar: BottomAppBar(
        // elevation: 10.0,
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: <Widget>[
            Expanded(
              flex: 1,
              child:Container(
                height: _footerHeight,
                child: RaisedButton.icon(
                label: Text('添加'),
                icon: Icon(Icons.add),
                color: Colors.yellow,
                onPressed: () {
                   Navigator.push(
                context,
                MaterialPageRoute(
                    //导航打开新视图
                    builder: (context) => CardAddPage()));
                },
              )
              ) 
            )
          ],
        ),
      ),
    );
  }

  Widget _buildListItem(BuildContext context, int index) {
    return new GestureDetector(
        onTap: () {
          // //处理点击事件
          // JYZModelData model =  jyzListData[index];
          // // var gasIds=model.gasid;
          //   Navigator.push(context, MaterialPageRoute(    //导航打开新视图
          //     builder: (context) => JYZDetailPage(model:model) //打开第二个页面，并传值，传递值的名称是model
          //   ));
        },
        child: Container(
            margin: EdgeInsets.fromLTRB(
                 ScreenUtil.getInstance().setWidth(5), ScreenUtil.getInstance().setHeight(15),  ScreenUtil.getInstance().setWidth(5), 0),
            child: Column(
              children: <Widget>[
                Row(children: <Widget>[
                  _leftImage(index),
                  // Expanded(
                  //   child: _rightColumn(index),
                  // ),
                ], crossAxisAlignment: CrossAxisAlignment.start),
                Divider(
                  height: 1,
                )
              ],
            )));
  }

  Widget _pd(Widget w, {double l, double t, double r, double b}) {
    //边距
    return Padding(
        padding: EdgeInsets.fromLTRB(
            ScreenUtil.getInstance().setWidth(l) ?? 0,
            ScreenUtil.getInstance().setHeight(t) ?? 0,
            ScreenUtil.getInstance().setWidth(r) ?? 0,
            ScreenUtil.getInstance().setHeight(b) ?? 0),
        child: w);
  }

  Widget _leftImage(int index) {
    //左图
    var image = new Image(
        image: AssetImage('images/icon_setup_bankcard.png'),
        width: ScreenUtil.getInstance().setHeight(100),
        height: ScreenUtil.getInstance().setHeight(100),
        fit: BoxFit.fill);
    return _pd(image, l:  ScreenUtil.getInstance().setWidth(20), t: 0, r: 5, b:  ScreenUtil.getInstance().setWidth(20) * 3);
  }

  Widget _rightColumn(int index) {
    var name = RichText(
        text: TextSpan(style: TextStyle(color: Colors.black), children: [
      TextSpan(text: 'name', style: TextStyle(fontSize: 14.0)),
      TextSpan(text: '默认', style: TextStyle(fontSize: 14.0)),
    ]));
  }
}
